#!/bin/bash

toInstallTheSoftware()
{
   #interactive
    read -p "you are sure you wang to install the uninstalled software?[y/n]" input
    if [ $input = 'y' ] 
    then
        #install the uninstalled software
        echo "you accept"
        echo 'Uninstalled software is:' ${uninstalled_software[*]}

        for uis in ${uninstalled_software[*]}
        do
            if [ $uis = "jgmenu" ] 
            then
                echo "jgmenu is installed!"
                sudo apt-get install libmenu-cache3 -y
                sudo dpkg -i /usr/lib/box_envirment/jgmenu_deb/jgmenu_4.1.0-1.1_amd64.deb
            else
                sudo apt-get install $uis -y
                if [ $? -ne 0 ] 
                then
                    echo "an error happend in install process !"
                fi
            fi
        done
    else
        exit
    fi 
}

check()
{

    #ask if to change the sourcelist
    

    #The set of software required to build the environment
    base_software=(xserver-xorg xinit openbox lightdm obmenu obconf lxterminal xfdesktop4 tint2 thunar papirus-icon-theme jgmenu)

    date >> log.text
    for software in ${base_software[*]}
    do
        #echo -e "$software"
        dpkg -s $software >/dev/null 2>&1
        if [ $? -eq 0 ] 
        then
            echo $software is exist >>log.text
        else
            echo $software is not exist >>log.text
            uninstalled_software="$uninstalled_software $software"
        fi
    done
    uninstalled_software=($uninstalled_software)

    #jduge uninstalled_software if is null
    if [ -z $uninstalled_software ] 
    then
        echo "there is no software that is uninstalled"
    else
        echo "---------------------------------------------------">>log.text
        echo 'Uninstalled software is:' ${uninstalled_software[*]}

        #ask user if he or she want to install the soft ware
        toInstallTheSoftware
    fi
}


#checkSoftwareInstalled
check

